package com.huicoo.forestmanager.adapter;

import android.support.annotation.Nullable;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huicoo.forestmanager.R;
import com.huicoo.forestmanager.base.BaseApplication;
import com.huicoo.forestmanager.network.bean.patrol.PatrollingTasksinif;
import com.huicoo.forestmanager.util.DisplayUtil;

import java.util.List;

/**
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2019/4/5		    Administrator
 */
public class ForestCampAdapter extends BaseQuickAdapter<PatrollingTasksinif, BaseViewHolder> {

    public ForestCampAdapter(@Nullable List<PatrollingTasksinif> data) {
        super(R.layout.adapter_forest_camp_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PatrollingTasksinif item) {
        if (helper.getLayoutPosition() % 2 == 0) {
            RelativeLayout relativeLayout = helper.getView(R.id.rl);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
            layoutParams.leftMargin = DisplayUtil.dp2px(BaseApplication.getMyApplication(), 10);
            layoutParams.rightMargin = DisplayUtil.dp2px(BaseApplication.getMyApplication(), 3);
            relativeLayout.setLayoutParams(layoutParams);
        } else {
            RelativeLayout relativeLayout = helper.getView(R.id.rl);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
            layoutParams.leftMargin = DisplayUtil.dp2px(BaseApplication.getMyApplication(), 3);
            layoutParams.rightMargin = DisplayUtil.dp2px(BaseApplication.getMyApplication(), 10);
            relativeLayout.setLayoutParams(layoutParams);
        }

        //设置时间
        helper.setText(R.id.time, item.getStartTime());

        //设置地址
        helper.setText(R.id.address,
                (item.getCounty() == null ? "" : item.getCounty().getName())
                        + (item.getTown() == null ? "" : item.getTown().name)
                        + (item.getVillage() == null ? "" : item.getVillage().name)
        );


        //内容
        helper.setText(R.id.content, item.getForestArea().getSerialNumber());


        if (item.getForestArea().getRecordStatus() == 0) {
            helper.setImageResource(R.id.iv_state, R.drawable.icon_waiting);
        } else if (item.getForestArea().getRecordStatus() == 1) {
            helper.setImageResource(R.id.iv_state, R.drawable.icon_doing);
        } else if (item.getForestArea().getRecordStatus() == 100) {
            helper.setImageResource(R.id.iv_state, R.drawable.icon_done);
        }

    }
}
